Background ImageΒΆ

This example presents the fastest way to load a background image. To load an image as the background, it must be the same width and height as the program.

from p5 import *

bg = None
y = 0

def setup():
    global bg
    size(720, 400)
    bg = load_image("moonwalk.jpg")

def draw():
    global img, y
    background(bg)

    stroke(226, 204, 0)
    line((0, y), (width, y))

    y += 1

    if y > height:
        y = 0

if __name__ == '__main__':
    run()